using UnityEngine;
using System;

public class GUITreeNode : GUINode
{
    public bool HandlesOnGUI = false;

    void Awake()
    {
        if (GetComponents<GUITreeNode>().Length>1)
            throw new Exception("A GameObject can't contain more than one GUITreeNode");
    }

    void OnGUI()
    {
        if (HandlesOnGUI)
            DrawGUI();
    }

    public override void DrawGUI()
    {
        for (int i=0, n=transform.childCount; i<n; ++i)
        {
            GameObject child = transform.GetChild(i).gameObject;
            DrawGUIComponents(child.GetComponents<GUINode>());
        }
    }

    protected virtual void DrawGUIComponents(GUINode[] components)
    {
        for (int i=0; i<components.Length; ++i)
            components[i].DrawGUI();
    }
}